-
Notifications
You must be signed in to change notification settings - Fork 9
/
TemplateView.swift
67 lines (65 loc) · 2.36 KB
/
TemplateView.swift
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
//
// TemplateView.swift
// Chord Provider
//
// © 2023 Nick Berendsen
//
import SwiftUI
/// SwiftUI `View` when creating a new document
struct TemplateView: View {
/// The ChordPro document
@Binding var document: ChordProDocument
/// The song struct
@Bindable var sceneState: SceneState
/// The FileBrowser model
@Environment(FileBrowser.self) private var fileBrowser
/// The dismiss environment
@Environment(\.dismiss) var dismiss
/// The title of the song
@State private var title: String = ChordProDocument.newTitle
/// The artist of the song
@State private var artist: String = ChordProDocument.newArtist
/// The body of the `View`
var body: some View {
VStack {
Text("Add a new song")
.font(.title)
HStack {
SongFolderView()
Divider()
.padding(.horizontal)
VStack {
Form {
TextField(
text: $title,
prompt: Text(ChordPro.Directive.title.details.label)
) {
Text(ChordPro.Directive.title.details.label)
}
TextField(
text: $artist,
prompt: Text(ChordPro.Directive.artist.details.label)
) {
Text(ChordPro.Directive.artist.details.label)
}
Button("Add song") {
/// Convert the meta data
var metaData: [String] = []
metaData.append(EditorView.format(directive: .title, argument: title))
metaData.append(EditorView.format(directive: .artist, argument: artist))
/// Add the meta data to the document
document.text = "\(metaData.joined())\n"
/// Close the sheet
dismiss()
}
.keyboardShortcut(.defaultAction)
.buttonStyle(.bordered)
}
.formStyle(.columns)
}
}
.padding()
}
.padding()
}
}